package cn.NewsServlet;

import cn.NewsDao.NewsDao1;
import cn.NewsDao.NewsDao4;
import cn.NewsDaoImpl.NewsDaoImpl1;
import cn.NewsDaoImpl.NewsDaoImpl4;
import cn.NewsService.NewsService;
import cn.NewsService.NewsService1;
import cn.NewsService.NewsService4;
import cn.NewsServiceImpl.NewsServiceImpl;
import cn.NewsServiceImpl.NewsServiceImpl1;
import cn.NewsServiceImpl.NewsServiceImpl4;
import cn.entity.News4;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

@WebServlet("/chakan")
public class ChakanServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {



    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String username=req.getParameter("username");
        String  password=req.getParameter("password");
        //NewsDao4 newsDao1 = new NewsDaoImpl4();
        NewsService4 newsService1 = new NewsServiceImpl4();
        List<News4> newsList=newsService1.getNewsList();
        //List<News4> newsList = newsDao1.getNewsList();
        PrintWriter printWriter=resp.getWriter();
        for (int i=0;i<newsList.size();i++){

            if (newsList.get(i).getUserName().equals(username)&&newsList.get(i).getPassword().equals(password)){
                printWriter.print(1);
                return;
            }else {
                printWriter.print(-1);
            }
        }
        //resp.setCharacterEncoding("text/html;charset=UTF-8");



        printWriter.flush();
        printWriter.close();



    }
}
